﻿Partial Public Class TunnelingEvents

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Debug.WriteLine("Button_Click: " & e.Source.ToString)
        e.Handled = False
    End Sub

    Private Sub Button_PreviewMouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
        Debug.WriteLine("Button_PreviewMouseDown: " & e.Source.ToString)
        e.Handled = False
    End Sub

    Private Sub Grid_PreviewMouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
        Debug.WriteLine("Grid_PreviewMouseDown: " & e.Source.ToString)
        e.Handled = False
    End Sub

    Private Sub Window_PreviewMouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
        Debug.WriteLine("Window_PreviewMouseDown: " & e.Source.ToString)
        e.Handled = False
    End Sub

    Private Sub TunnelingEvents_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Me.Button1.AddHandler(Button.PreviewMouseDownEvent, New RoutedEventHandler(AddressOf Button_PreviewMouseDown))
        Me.gridLayoutRoot.AddHandler(Button.PreviewMouseDownEvent, New RoutedEventHandler(AddressOf Grid_PreviewMouseDown))
        Me.windowTunnelingEvents.AddHandler(Button.PreviewMouseDownEvent, New RoutedEventHandler(AddressOf Window_PreviewMouseDown))
    End Sub

    Private Sub TunnelingEvents_Unloaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Unloaded
        Me.Button1.RemoveHandler(Button.PreviewMouseDownEvent, New RoutedEventHandler(AddressOf Button_PreviewMouseDown))
        Me.gridLayoutRoot.RemoveHandler(Button.PreviewMouseDownEvent, New RoutedEventHandler(AddressOf Grid_PreviewMouseDown))
        Me.windowTunnelingEvents.RemoveHandler(Button.PreviewMouseDownEvent, New RoutedEventHandler(AddressOf Window_PreviewMouseDown))
    End Sub

End Class
